'''
Author: GlenZhao
Date: 2025-05-08 11:04:31
LastEditors: GlenZhao
LastEditTime: 2025-05-09 12:08:34
Description: 
'''
# -*- coding: utf-8 -*-
from pydantic import BaseModel, ConfigDict, model_serializer

from db.base import BaseSchemas
from core.data_types import TimeStr
from application import constant


class Job(BaseModel):
    task_id: str
    task_name: str
    task_type: str
    jl_account: str| None = ''
    account_id: str| None = ''
    max_threshold: int| None = ''
    promo_type: str| None = ''
    op_type: str| None = ''
    plan_id: str| None = ''
    status: str| None = ''
    activation_code: str

     # 新增字段
    statistics_strategy: str | None = ''
    customer_operation_count: int | None = 0
    operation_multiplier: float | None = ''
    operation_plan_types: list | None = []
    plan_configs: dict | None = ''
    white_list: str | None = ''
    remark: str | None = ''


class JobOut(Job, BaseSchemas):
    model_config = ConfigDict(from_attributes=True)
    

class AddJobIn(BaseModel):
    task_name: str
    task_type: str
    jl_account: str | None = ''
    account_id: str | None = ''
    max_threshold: int| None = 100
    promo_type: str | None = ''
    op_type: str | None = ''
    plan_id: str | None = ''
    activation_code: str

     # 新增字段
    statistics_strategy: str | None = '智能统计'
    customer_operation_count: int | None = 0
    operation_multiplier: float | None = 1.5
    operation_plan_types: list | None = []
    plan_configs: dict | None = {}
    white_list: str | None = ''
    remark: str | None = ''

class DeleteJobIn(BaseModel):
    task_id: str


class PutJobStatusIn(BaseModel):
    task_id: str
    status: constant.JobStatusEnum
    remark: str | None = ''


class Schedule(BaseModel):
    schedule_id: str
    name: str
    execute_time: TimeStr
    activation_code: str
    task_ids: str

class ScheduleOut(Schedule, BaseSchemas):
    model_config = ConfigDict(from_attributes=True)
    tasks: list[JobOut] | None = []


class AddScheduleIn(BaseModel):
    name: str
    execute_time: TimeStr
    task_ids: list[str]
    activation_code: str

    @model_serializer
    def serialize_model(self) -> dict:
        return {
            'name': self.name,
            'execute_time': self.execute_time,
            'task_ids': ','.join(self.task_ids),
            'activation_code': self.activation_code,
        }
    

class DeleteScheduleIn(BaseModel):
    schedule_id: str


class JobLogs(BaseModel):
    task_id: str
    text: str
    running_time: str


class JobLogsOut(JobLogs, BaseSchemas):
    model_config = ConfigDict(from_attributes=True)


class AddJobLogsIn(JobLogs):
    pass